@echo off
:: MXSPLI-ShareMX
:: MixSoft Programming Language Interpreter
:: Version v11_ShareMXv2
:: Developers: Mihail Mojsoski
set cmd=%~1
if "%1"=="[" set /a open=%open%+1
if "%1"=="]" set /a open=%open%-1
if "%1"=="at" goto at
if "%1"=="execute" goto execute
if "%1"=="code" goto code
if "%1"=="if" goto compare
if "%pmode%"=="at" goto atc
if "%pmode%"=="code" goto codetc
set /a sError=%sError%+1
set lasterror=%LNG_ATLINE% %line%: {%LNG_COMMANDERROR%} %LNG_CMDFUN% "%~1" %LNG_NOTALLOWED%
echo %LNG_ATLINE% %line%: {%LNG_COMMANDERROR%} %LNG_CMDFUN% "%~1" %LNG_NOTALLOWED%
if "%debug%"=="1" echo [%LNG_DBG0%] %LNG_ATLINE% %line%: {%LNG_COMMANDERROR%} %LNG_CMDFUN% "%~1" %LNG_NOTALLOWED% >> "%mypath%\%debugpath%"
goto :end

:compare
set ifcorrect=false
set var1=%2
set comp=%~3
set var2=%4
set iftrue=%~5
set else=%~6
set ifelse=%~7
call set var11=%%%var1%%%
call set var22=%%%var2%%%
if "%var11%"=="" set var11=%~2
if "%var22%"=="" set var22=%~4
if "%comp%"=="EQU" goto docomp
if "%comp%"=="NEQ" goto docomp
if "%comp%"=="LSS" goto docomp
if "%comp%"=="LEQ" goto docomp
if "%comp%"=="GTR" goto docomp
if "%comp%"=="GEQ" goto docomp
set /a sError=%sError%+1
set lasterror=%LNG_ATLINE% %line%: {%LNG_COMMANDERROR%} %LNG_USEIF%
echo %LNG_ATLINE% %line%: {%LNG_COMMANDERROR%} %LNG_USEIF%
if "%debug%"=="1" echo [%LNG_DBG0%] %LNG_ATLINE% %line%: {%LNG_COMMANDERROR%} %LNG_USEIF% >> "%mypath%\%debugpath%"
goto end

:docomp
if "%var11%" %comp% "%var22%" set ifcorrect=true
if "%ifcorrect%"=="true" (
	call :execute execute "%iftrue%"
)
if "%ifcorrect%"=="false" (
	if "%else%"=="else" (
		call :execute execute "%ifelse%"
	)
)
goto end

:callout
if "%cmd:~0,1%"=="$" goto define
call :out %1 %2 %3 %4 %5 %6 %7 %8 %9
goto end


:codetc
if "%open%"=="%endcode%" (
 set pmode=nul
 set endprog=1
 goto end
)
goto callout

:code
set fname=%~2
set f%fname%=%line%
set endcode=%open%
set pmode=code
goto end

:execute
set /a open=%open%-1
if "%~2"=="file" goto exout
set fname=%~2
if "%debug%"=="1" goto end
call set line=%%f%fname%%%
goto end

:exout
if not exist "%~3.%ext%" (
 set /a sError=%sError%+1
 set lasterror=%LNG_ATLINE% %line%: {%LNG_COMMANDERROR%} %LNG_THEFILE% "%~3" %LNG_EXISTEXEC%
 echo %LNG_ATLINE% %line%: {%LNG_COMMANDERROR%} %LNG_THEFILE% "%~3" %LNG_EXISTEXEC%
 if "%debug%"=="1" echo [%LNG_DBG0%] %LNG_ATLINE% %line%: {%LNG_COMMANDERROR%} %LNG_THEFILE% "%~3" %LNG_EXISTEXEC% >> "%mypath%\%debugpath%"
 goto end
)
set file=%cd%\%~3.%ext%
set reset=1
goto end

:atc
if "%open%"=="%endat%" set pmode=nul
if "%1"=="use" goto use
goto end

:use
if not "%~3"=="as" (
	if not "%~3"=="AS" (
		set /a sError=%sError%+1
		echo %LNG_ATLINE% %line%: {%LNG_SYNTAXERROR%} %LNG_UNEXPECTED% "%~3" %LNG_USEAS%
		set lasterror=%LNG_ATLINE% %line%: {%LNG_SYNTAXERROR%} %LNG_UNEXPECTED% "%~3" %LNG_USEAS%
		if "%debug%"=="1" echo [%LNG_DBG0%] %LNG_ATLINE% %line%: {%LNG_SYNTAXERROR%} %LNG_UNEXPECTED% "%~3" %LNG_USEAS% >> "%mypath%\%debugpath%"
		goto end
	)
)
set cmd%~4=%mypath%\lib\%lib%.bat
set ext%~4=%~2
goto end

:at
if not exist "%mypath%\lib\%~2.bat" (
		set /a sError=%sError%+1
		echo %LNG_ATLINE% %line%: {%LNG_LIBRARYERROR%} %LNG_UNKLIB% %~2
		set lasterror=%LNG_ATLINE% %line%: {%LNG_LIBRARYERROR%} %LNG_UNKLIB% %~2
		if "%debug%"=="1" echo [%LNG_DBG0%] %LNG_ATLINE% %line%: {%LNG_LIBRARYERROR%} %LNG_UNKLIB% %~2 >> "%mypath%\%debugpath%"
		goto end
)
set lib=%2
set endat=%open%
set pmode=at
goto end

:define
if "%~2"=="add" goto varadd
if "%~2"=="take" goto vartake
if "%~2"=="calc" goto varcalc
if "%~1"=="" goto end
if "%~2"=="" goto end
if "%~2"=="is" (
 set %1=%~3
) else (
 	set /a sError=%sError%+1
	echo %LNG_ATLINE% %line%: {%LNG_SYNTAXERROR%} %LNG_UNEXPECTED% "%~2" %LNG_VARIS%
	set lasterror=%LNG_ATLINE% %line%: {%LNG_SYNTAXERROR%} %LNG_UNEXPECTED% "%~2" %LNG_VARIS%
	if "%debug%"=="1" echo [%LNG_DBG0%] %LNG_ATLINE% %line%: {%LNG_SYNTAXERROR%} %LNG_UNEXPECTED% "%~2" %LNG_VARIS% >> "%mypath%\%debugpath%"
)
goto end

:varcalc
set /a %1=%~3
goto end

:varadd
set tmp1=%~1
call set tmp2=%%%tmp1%%%
set /a %~1=%tmp2%+%~3
goto end

:vartake
set tmp1=%~1
call set tmp2=%%%tmp1%%%
set /a %~1=%tmp2%-%~3
goto end

:out
if "%1"=="[" goto end
if "%1"=="]" goto end
set command=%~1
set tmp=cmd%command%
call set c1=%%%tmp%%%
if not exist %c1% (
 	set /a sError=%sError%+1
	echo %LNG_ATLINE% %line%: {%LNG_LIBRARYERROR%} %LNG_UNKCMD% "%~1"
	set lasterror=%LNG_ATLINE% %line%: {%LNG_LIBRARYERROR%} %LNG_UNKCMD% "%~1".
	if "%debug%"=="1" echo [%LNG_DBG0%] %LNG_ATLINE% %line%: {%LNG_LIBRARYERROR%} %LNG_UNKCMD% "%~1" >> "%mypath%\%debugpath%"
	goto end
)
set tmp=ext%command%
call set c2=%%%tmp%%%
call %c1% %c2% %2 %3 %4 %5 %6 %7 %8 %9
:end